#ifndef REGISTER_H_

#define REGISTER_H_

#ifdef WIN32
#define REGISTERS_BASE                      0
#endif

/*** RegisterAddress ***/
#define WISH_BASE                           REGISTERS_BASE

#define SYS_CONF_ADDR_SPACE                 4*40
#define SYS_CONF_IDENT                      4*0
#define SYS_CONF_SVN_REF_NUM                4*1
#define SYS_CONF_VLAN_TAG                   4*2
#define SYS_CONF_IPv4_ADDR                  4*3
#define SYS_CONF_IPv6_ADDR0                 4*4
#define SYS_CONF_IPv6_ADDR1                 4*5
#define SYS_CONF_IPv6_ADDR2                 4*6
#define SYS_CONF_IPv6_ADDR3                 4*7
#define SYS_CONF_MASTER_CONF0               4*8
#define SYS_CONF_MASTER_CONF1               4*9
#define SYS_CONF_MASTER_CONF2               4*10
#define SYS_CONF_ERROR                      4*11
#define SYS_CONF_TOD_SEC_LOW                4*12
#define SYS_CONF_TOD_SEC_HIGH               4*13
#define SYS_CONF_PTP_TIME_NANOSEC           4*14
#define SYS_CONF_PTP_TIME_SEC_LOW           4*15
#define SYS_CONF_PTP_TIME_SEC_HIGH          4*16
#define SYS_CONF_PHY0_STATUS                4*17
#define SYS_CONF_PPS_TIMESTAMP              4*18
#define SYS_CONF_CLOCK_WIDTH_SUBNS          4*19
#define SYS_CONF_CLOCK_WIDTH_NS             4*20
#define SYS_CONF_USE_INTERNAL_CLOCK         4*21


#define MAC_BASE_ADDR                       SYS_CONF_ADDR_SPACE
#define MAC_ADDR_SPACE                      4*40
#define MAC_IDENT                           MAC_BASE_ADDR + 4*0
#define MAC_UNICAST_MAC_ADDR_H              MAC_BASE_ADDR + 4*1
#define MAC_UNICAST_MAC_ADDR_L              MAC_BASE_ADDR + 4*2
#define MAC_MULTICAST_MAC_TAB_0             MAC_BASE_ADDR + 4*3
#define MAC_MULTICAST_MAC_TAB_1             MAC_BASE_ADDR + 4*4
#define MAC_MULTICAST_MAC_TAB_2             MAC_BASE_ADDR + 4*5
#define MAC_MULTICAST_MAC_TAB_3             MAC_BASE_ADDR + 4*6
#define MAC_MULTICAST_MAC_TAB_4             MAC_BASE_ADDR + 4*7
#define MAC_MULTICAST_MAC_TAB_5             MAC_BASE_ADDR + 4*8
#define MAC_COUNTER_CRC_ERR                 MAC_BASE_ADDR + 4*9
#define MAC_COUNTER_NIOS_PKT                MAC_BASE_ADDR + 4*10
#define MAC_COUNTER_PTP_PKT                 MAC_BASE_ADDR + 4*11
#define MAC_COUNTER_DISC_PKT                MAC_BASE_ADDR + 4*12
#define MAC_COUNTER_DISC_DELREQ             MAC_BASE_ADDR + 4*13
#define MAC_COUNTER_PHY_RX_FIFO_FULL        MAC_BASE_ADDR + 4*14
#define MAC_COUNTER_PHY_TX_FIFO_FULL        MAC_BASE_ADDR + 4*15
#define MAC_COUNTER_ALL_RX_PKT              MAC_BASE_ADDR + 4*16

#define NIOS_NETW_ITF_BASE_ADDR                MAC_BASE_ADDR + MAC_ADDR_SPACE
#define NIOS_NETW_ITF_ADDR_SPACE               4*4112
#define NIOS_NETW_ITF_IDENT                    NIOS_NETW_ITF_BASE_ADDR
#define NIOS_NETW_ITF_INT_REQ                  NIOS_NETW_ITF_BASE_ADDR + 4*1
#define NIOS_NETW_ITF_INT_MASK                 NIOS_NETW_ITF_BASE_ADDR + 4*2
#define NIOS_NETW_ITF_TX_STATE                 NIOS_NETW_ITF_BASE_ADDR + 4*3
#define NIOS_NETW_ITF_TX_CONFIG                NIOS_NETW_ITF_BASE_ADDR + 4*4
#define NIOS_NETW_ITF_RX_STATE                 NIOS_NETW_ITF_BASE_ADDR + 4*5
#define NIOS_NETW_ITF_RX_TS0                   NIOS_NETW_ITF_BASE_ADDR + 4*6
#define NIOS_NETW_ITF_RX_TS1                   NIOS_NETW_ITF_BASE_ADDR + 4*7
#define NIOS_NETW_ITF_RX_TS2                   NIOS_NETW_ITF_BASE_ADDR + 4*8
#define NIOS_NETW_ITF_RX_LOST_CNT              NIOS_NETW_ITF_BASE_ADDR + 4*9
#define NIOS_NETW_ITF_TX_LOST_CNT              NIOS_NETW_ITF_BASE_ADDR + 4*10
#define NIOS_NETW_ITF_RX_ASSEMBLY_LOST_CNT     NIOS_NETW_ITF_BASE_ADDR + 4*11
#define NIOS_NETW_ITF_TX_BUF                   NIOS_NETW_ITF_BASE_ADDR + 4*12
#define NIOS_NETW_ITF_RX_BUF                   NIOS_NETW_ITF_BASE_ADDR + 4*13
#define NIOS_NETW_ITF_TX_DELAY                 NIOS_NETW_ITF_BASE_ADDR + 4*14
#define NIOS_NETW_ITF_RX_DELAY                 NIOS_NETW_ITF_BASE_ADDR + 4*15
#define NIOS_NETW_ITF_TX_DELAY_SLAVE           NIOS_NETW_ITF_BASE_ADDR + 4*16
#define NIOS_NETW_ITF_RX_DELAY_SLAVE           NIOS_NETW_ITF_BASE_ADDR + 4*17

#define SLAVE_MGM_BASE_ADDR                 NIOS_NETW_ITF_BASE_ADDR + NIOS_NETW_ITF_ADDR_SPACE
#define SLAVE_MGM_ADDR_SPACE                4*32784
#define SLAVE_MGM_IDENT                     SLAVE_MGM_BASE_ADDR
#define SLAVE_MGM_DELAY_OV_CNT_REG          SLAVE_MGM_BASE_ADDR + 4*1
// Space left!
#define SLAVE_MGM_LUT_CONFIG_REG            SLAVE_MGM_BASE_ADDR + 4*3
#define SLAVE_MGM_TABLE_START_ADDR          SLAVE_MGM_BASE_ADDR + 4*4
#define SLAVE_MGM_TABLE_END_ADDR            SLAVE_MGM_TABLE_START_ADDR + (2048*8*4)
#define SLAVE_MGM_LUT_START_ADDR            SLAVE_MGM_TABLE_END_ADDR
#define SLAVE_MGM_LUT_END_ADDR              SLAVE_MGM_LUT_START_ADDR + (2048*2*4)

#define HOST_REG_BASE_ADDR                  SLAVE_MGM_BASE_ADDR + SLAVE_MGM_ADDR_SPACE
#define HOST_REG_ADDR_SPACE                 36
#define HOST_REG_USER0                      HOST_REG_BASE_ADDR + 4*0
#define HOST_REG_USER1                      HOST_REG_BASE_ADDR + 4*1
#define HOST_REG_USER2                      HOST_REG_BASE_ADDR + 4*2
#define HOST_REG_USER3                      HOST_REG_BASE_ADDR + 4*3
#define HOST_REG_TABLE0_START_ADDR          HOST_REG_BASE_ADDR + 4*4
#define HOST_REG_TABLE0_END_ADDR            HOST_REG_TABLE0_START_ADDR + 4*35



/*** Register Bits ***/
// SLAVE TABLE
#define SLAVE_TAB_IPV4      0
#define SLAVE_TAB_MAC0      4
#define SLAVE_TAB_MAC4      8
#define SLAVE_TAB_SYNC      12
#define SLAVE_TAB_ANCE      16
#define SLAVE_TAB_IPV6_1    20
#define SLAVE_TAB_IPV6_2    24
#define SLAVE_TAB_IPV6_3    28
#define SLAVE_TAB_IPV6_4    32

// NIOS_NETW_ITF_INT_REQ
#define NIOS_NETW_TX_FIFO_FULL_BIT          0x1
#define NIOS_NETW_TX_FIFO_ALMOST_FULL_BIT   0x2
#define NIOS_NETW_RX_FIFO_READY_BIT         0x4
#define NIOS_NETW_RX_FIFO_OVERRUN_BIT       0x8


/*** PLL monitor registers ***/
#define PPS_PLL_ADDR                        HOST_REG_TABLE0_END_ADDR + 4
#define PPS_PLL_SPACE                       4


/*** SPI master additional registers ***/
#define SPI_MASTER_ADDR                     PPS_PLL_ADDR + 4*PPS_PLL_SPACE
#define SPI_STATUS_REG                      SPI_MASTER_ADDR

#define END_REGISTER_OFFSET                 SPI_STATUS_REG + 4

// crma mocking registers

#ifndef _MOCK_REG_
#define _MOCK_REG_
uint32_t    mock_registers[END_REGISTER_OFFSET-REGISTERS_BASE];
#endif

# endif

